#include <STC15F2K60S2.H>
#include <led.h>
#include <seg.h>
#include <key.h>
#include <init.h>
 
unsigned char ucLed[]={0,1,0,0,0,0,0,0};//0灭1亮
unsigned char seg_Buff[]={0,1,2,3,4,5,6,7};//{10,10,10,10,10,10,10,10};
unsigned char segPos=0,Key_Val,Key_Old,Key_Down,Key_Up;
unsigned char keyCnt=0;

void Timer0Init(void)		//1毫秒@12.000MHz
{
	AUXR &= 0x7F;		//定时器时钟12T模式
	TMOD &= 0xF0;		//设置定时器模式
	TL0 = 0x18;		//设置定时初值
	TH0 = 0xFC;		//设置定时初值
	TF0 = 0;		//清除TF0标志
	TR0 = 1;		//定时器0开始计时
	
	ET0 = 1;
	EA = 1;
}

void time0Service() interrupt 1
{
	 
		if(++segPos==8)segPos=0;
		if(++keyCnt==10)keyCnt=0;
	
	
		led_disp(ucLed);
		seg_disp(segPos,seg_Buff[segPos],0);
		
}

void key_proc()
{
	if(keyCnt!=0)return ;
	keyCnt=1;
	
	Key_Val = readKey();
	Key_Down = Key_Val&(Key_Val^Key_Old);
	Key_Up =  ~Key_Val&(Key_Val^Key_Old);
	Key_Old = Key_Val;
	
	switch(Key_Down)
	{
		case 4:
			seg_Buff[0]=4;
			break;
		case 5:
			break;
		case 6:
			break;
		case 7:
			break;
	}
	
	
}


void main()
{
	System_Init();
	Timer0Init();
	
	while(1){
		key_proc();
	}
}